package com.controller;

import com.Dto.CounselorInfoDto;
import com.Dto.GuidanceSessionOfSupervisorDto;
import com.Dto.SupervisorInfoDto;
import com.common.Result;
import com.mapper.CounselorBoundMapper;
import com.pojo.CounselorBound;
import com.pojo.GuidanceSession;
import com.service.SupervisorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping("Supervisor")
public class SupervisorController {

    @Autowired
    private SupervisorService supervisorService;

    /**督导查询本月排班
     *
     * @param userId
     * @return
     */

    @GetMapping("/getSupervisorDates")
    public Result<List<LocalDate>> getSupervisorDates(@RequestParam("userId") Integer userId){
        Result<List<LocalDate>> listResult = new Result<>();
        try{
            List<LocalDate> dateList = supervisorService.getDatesByUserIdAndCurrentMonth(userId);
            listResult.setSuc(dateList);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            listResult.setFail("获取失败");
        }
        return listResult;

    }

    /**督导查看援助会话
     *
     * @param userId
     * @return
     */
    @GetMapping("/getGuidanceSessions")
    public Result<List<GuidanceSessionOfSupervisorDto>> getGuidanceSessions(@RequestParam("userId") Integer userId){
        Result<List<GuidanceSessionOfSupervisorDto>> listResult = new Result<>();
        try{
            List<GuidanceSessionOfSupervisorDto> sessionList = supervisorService.getGuidanceSessionByUserId(userId);

            listResult.setSuc(sessionList);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            listResult.setFail("获取失败");
        }
        return listResult;
    }

    /**督导查看绑定咨询师
     *
     * @param userId
     * @return
     */
    @GetMapping("/getCounselorBound")
    public Result<List<CounselorBound>> getCounselorBound(@RequestParam("userId")Integer userId){
        Result<List<CounselorBound>> listResult = new Result<>();

        try{
            List<CounselorBound> counselorBoundList = supervisorService.getCounselorBound(userId);
            listResult.setSuc(counselorBoundList);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            listResult.setFail("获取失败");
        }
        return listResult;
    }

    /**督导查询个人信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/getSupervisorInfo")
    public Result<List<SupervisorInfoDto>> getSupervisorInfo(@RequestParam("userId") Integer userId){
        Result<List<SupervisorInfoDto>> listResult = new Result<>();
        try{
            List<SupervisorInfoDto> info = supervisorService.getSupervisorInfoByUserId(userId);

            listResult.setSuc(info);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            listResult.setFail("获取失败");
        }
        return listResult;
    }

}
